package com.qyhl.module_practice.score.mine.bill;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeScoreBillBean;

import java.util.List;

public class PracticeScoreBillModel implements PracticeScoreBillContract.PracticeScoreBillModel {
    private PracticeScoreBillPresenter mPresenter;

    PracticeScoreBillModel(PracticeScoreBillPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String volId, String year, final String month) {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_SCORE_BILL)
                .params("volId", volId)
                .params("year", year)
                .params("month", month)
                .execute(new SimpleCallBack<List<PracticeScoreBillBean>>() {

                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何记录！");
                        } else {
                            mPresenter.setError("请求出错，请稍后再试！");
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeScoreBillBean> practiceScoreBillBeans) {
                        if (practiceScoreBillBeans != null && practiceScoreBillBeans.size() > 0) {
                            mPresenter.setList(practiceScoreBillBeans);
                        } else {
                            mPresenter.setError("暂无任何记录！");
                        }
                    }
                });
        
    }
}
